{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "######################################################################\n",
    "#\n",
    "# 遗传算法主体部分\n",
    "#\n",
    "######################################################################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import time\n",
    "import numpy as np\n",
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "distance = lambda a, b: math.sqrt((b[0] - a[0])**2 + (b[1] - a[1])**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 计算individual的适应度值\n",
    "def Func(individual, city_location):\n",
    "    ret = 0\n",
    "    for i in range(len(individual) - 1):\n",
    "        ret += distance(city_location[individual[i]], city_location[individual[i + 1]])\n",
    "    return 1000 / float(ret + distance(city_location[individual[-1]], city_location[individual[0]]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 初始化城市坐标\n",
    "def LoadData(city_numble):\n",
    "    return np.random.uniform(0, 100, size=[city_numble, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 随机初始化种群\n",
    "def Initialize(city_numble, individual_n):\n",
    "    ret = []\n",
    "    for _ in range(individual_n):\n",
    "        ret.append(np.random.choice(a=city_numble, size=city_numble,replace=False))\n",
    "    return np.array(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 交叉算子\n",
    "def Crossover(parent1, parent2, city_numble):\n",
    "    i = np.random.randint(0, city_numble - 2)\n",
    "    j = np.random.randint(i + 1, city_numble)\n",
    "    child1 = parent1.copy()\n",
    "    child2 = parent2.copy()\n",
    "    temp_parent = []\n",
    "    for temp in parent2:\n",
    "        if temp in parent1[i: j]:\n",
    "            temp_parent.append(temp)\n",
    "    child1[i: j] = temp_parent\n",
    "\n",
    "    temp_parent = []\n",
    "    for temp in parent1:\n",
    "        if temp in parent2[i: j]:\n",
    "            temp_parent.append(temp)\n",
    "    child2[i: j] = temp_parent\n",
    "\n",
    "    return child1, child2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 变异算子\n",
    "def Variation(parent, city_numble):\n",
    "    i = np.random.randint(0, city_numble - 2)\n",
    "    j = np.random.randint(i + 1, city_numble)\n",
    "    child = parent.copy()\n",
    "    temp = child[i: j]\n",
    "    np.random.shuffle(temp)\n",
    "    child[i: j] = temp\n",
    "    return child"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 选择算子\n",
    "def Selection(v):\n",
    "    exp_v = np.exp(v)\n",
    "    sum_exp_v = np.sum(exp_v)\n",
    "    return exp_v / sum_exp_v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 进化\n",
    "def Evolution(population, city_location, cross_rate, vary_rate):\n",
    "    fitness = []\n",
    "    for i in range(len(population)):\n",
    "        fitness.append(Func(population[i], city_location))\n",
    "    select_p = Selection(fitness)\n",
    "\n",
    "    choices = np.random.choice(a=len(population), size=len(population), replace=True, p=select_p)\n",
    "    new_population = population[choices]\n",
    "\n",
    "    for i in range(int(len(population) / 2)):\n",
    "        coin = np.random.random()\n",
    "        if coin < cross_rate:\n",
    "            new_population[i], new_population[i * 2] = Crossover(population[i], population[i * 2], len(city_location))\n",
    "        if coin < vary_rate:\n",
    "            new_population[i] = Variation(population[i], len(city_location))\n",
    "\n",
    "    argmax_value_index = np.argmax(fitness)\n",
    "    return fitness[argmax_value_index], population[argmax_value_index], new_population"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 97.97626084  71.95749894]\n",
      " [ 30.64579597  42.99766655]\n",
      " [ 72.56786805  47.48161899]\n",
      " [ 71.36233504  68.00325689]\n",
      " [  7.60730558  51.57608364]\n",
      " [ 76.49656269  25.32900026]\n",
      " [ 25.16178328  42.14474437]\n",
      " [ 98.95868997  19.67144799]\n",
      " [ 29.25215339   8.27894332]\n",
      " [ 42.58009012  97.39446108]\n",
      " [ 80.74674162  68.20738687]\n",
      " [ 45.19346054  83.9653453 ]\n",
      " [ 63.62309701  87.64040929]\n",
      " [  7.63223634  21.19996038]\n",
      " [  1.33566803  62.18876505]\n",
      " [ 11.1595988   73.91400851]\n",
      " [ 10.29041198  72.32059031]\n",
      " [ 22.21430717  81.95833968]\n",
      " [ 32.60945479   0.79376482]\n",
      " [ 21.78603164  84.12699046]]\n"
     ]
    }
   ],
   "source": [
    "### start_time 程序开始运行时间\n",
    "start_time = time.time()\n",
    "### city_numble 城市数量\n",
    "city_numble = 20\n",
    "### individual_n 每代种群个体数量\n",
    "individual_n = 10\n",
    "### 迭代次数\n",
    "iteration_times = 300\n",
    "### 交叉概率， [0, 1]\n",
    "cross_rate = 1\n",
    "### 变异概率, [0, 1]\n",
    "vary_rate = 1\n",
    "### 每次迭代存储最大适应度值\n",
    "max_fitness = 0\n",
    "### 目前最好的个体\n",
    "best_individual = []\n",
    "### 每次迭代存储最好的个体\n",
    "best_individuals = []\n",
    "### 每次迭代存储最好的适应度值\n",
    "best_fitness = []\n",
    "\n",
    "### 初始化城市坐标\n",
    "city_location = LoadData(city_numble)\n",
    "print(city_location)\n",
    "### 初始化种群\n",
    "population = Initialize(city_numble, individual_n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 best fitness: 0.9818008207912625\tmin distance: 1018.5365288186154\n",
      "1 best fitness: 1.052314979457825\tmin distance: 950.2858170043547\n",
      "2 best fitness: 1.081736342749458\tmin distance: 924.4396813536762\n",
      "3 best fitness: 1.081736342749458\tmin distance: 924.4396813536762\n",
      "4 best fitness: 1.081736342749458\tmin distance: 924.4396813536762\n",
      "5 best fitness: 1.081736342749458\tmin distance: 924.4396813536762\n",
      "6 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "7 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "8 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "9 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "10 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "11 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "12 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "13 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "14 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "15 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "16 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "17 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "18 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "19 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "20 best fitness: 1.0955410937883578\tmin distance: 912.790953867391\n",
      "21 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "22 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "23 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "24 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "25 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "26 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "27 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "28 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "29 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "30 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "31 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "32 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "33 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "34 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "35 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "36 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "37 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "38 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "39 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "40 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "41 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "42 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "43 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "44 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "45 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "46 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "47 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "48 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "49 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "50 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "51 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "52 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "53 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "54 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "55 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "56 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "57 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "58 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "59 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "60 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "61 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "62 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "63 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "64 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "65 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "66 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "67 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "68 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "69 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "70 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "71 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "72 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "73 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "74 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "75 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "76 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "77 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "78 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "79 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "80 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "81 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "82 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "83 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "84 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "85 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "86 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "87 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "88 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "89 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "90 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "91 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "92 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "93 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "94 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "95 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "96 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "97 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "98 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "99 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "100 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "101 best fitness: 1.198683198262128\tmin distance: 834.2487835399859\n",
      "102 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "103 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "104 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "105 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "106 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "107 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "108 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "109 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "110 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "111 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "112 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "113 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "114 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "115 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "116 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "117 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "118 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "119 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "120 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "121 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "122 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "123 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "124 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "125 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "126 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "127 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "128 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "129 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "130 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "131 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "132 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "133 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "134 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "135 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "136 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "137 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "138 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "139 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "140 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "141 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "142 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "143 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "144 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "145 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "146 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "147 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "148 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "149 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "150 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "151 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "152 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "153 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "154 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "155 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "156 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "157 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "158 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "159 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "160 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "161 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "162 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "163 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "164 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "165 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "166 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "167 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "168 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "169 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "170 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "171 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "172 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "173 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "174 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "175 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "176 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "177 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "178 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "179 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "180 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "181 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "182 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "183 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "184 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "185 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "186 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "187 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "188 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "189 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "190 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "191 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "192 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "193 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "194 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "195 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "196 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "197 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "198 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "199 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "200 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "201 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "202 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "203 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "204 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "205 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "206 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "207 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "208 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "209 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "210 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "211 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "212 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "213 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "214 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "215 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "216 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "217 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "218 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "219 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "220 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "221 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "222 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "223 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "224 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "225 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "226 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "227 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "228 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "229 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "230 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "231 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "232 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "233 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "234 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "235 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "236 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "237 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "238 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "239 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "240 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "241 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "242 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "243 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "244 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "245 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "246 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "247 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "248 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "249 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "250 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "251 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "252 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "253 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "254 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "255 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "256 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "257 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "258 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "259 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "260 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "261 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "262 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "263 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "264 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "265 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "266 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "267 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "268 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "269 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "270 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "271 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "272 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "273 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "274 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "275 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "276 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "277 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "278 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "279 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "280 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "281 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "282 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "283 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "284 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "285 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "286 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "287 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "288 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "289 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "290 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "291 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "292 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "293 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "294 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "295 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "296 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "297 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "298 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "299 best fitness: 1.2928529231992736\tmin distance: 773.4831874962356\n",
      "Total time:  0.352064847946167\n",
      "Max fitness:  1.2928529231992736\n",
      "Min distance:  773.4831874962356\n",
      "Best individual:  [ 9  1 13 18  3 10  0  7 16 19 11 15  6 17  4 14  8  5  2 12]\n"
     ]
    }
   ],
   "source": [
    "for i in range(iteration_times):\n",
    "    last_max_fitness, last_best_individual, population = Evolution(population, city_location, cross_rate, vary_rate)\n",
    "    if last_max_fitness > max_fitness:\n",
    "        max_fitness = last_max_fitness\n",
    "        best_individual = last_best_individual\n",
    "    best_fitness.append(max_fitness)\n",
    "    best_individuals.append(last_best_individual)\n",
    "    print(str(i) + \" best fitness: \" + str(max_fitness) + \"\\tmin distance: \" + str(1000 / max_fitness))\n",
    "\n",
    "end_time = time.time()\n",
    "\n",
    "print(\"Total time: \", (end_time - start_time))\n",
    "print(\"Max fitness: \", max_fitness)\n",
    "print(\"Min distance: \", 1000 / max_fitness)\n",
    "print(\"Best individual: \", best_individual)\n",
    "######################################################################"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "######################################################################\n",
    "#\n",
    "# 绘图部分\n",
    "#\n",
    "######################################################################\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 定义画布\n",
    "fig, ax = plt.subplots()\n",
    "xdata, ydata = [], []\n",
    "ln, = plt.plot([], [],'ro',animated=True,color='black',markersize = 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 初始化函数\n",
    "def PlotInit():\n",
    "    ax.set_xlabel('iteration time')\n",
    "    ax.set_ylabel('Distance')\n",
    "    return ln, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### 绘画迭代过程\n",
    "def PlotDistance():\n",
    "    xdata = np.arange(iteration_times)\n",
    "    ydata = [1000 / i for i in best_fitness]\n",
    "    ax.plot(xdata, ydata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZMAAAEPCAYAAACHuClZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGcNJREFUeJzt3XvUXXWd3/H3B0K4OBLjBaigiHKLjoqMoP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S6+mE4UJtu2WBOku7xDDR\n7i7AW6rqigcVJs8DfjXn538OPKOqtjTnM/bp2ka/+9puS9fyA+z8v8WtXcvbtm+vqqq5lfr2/f1W\n26Rh8JyJdhfbf5HfA3SfLF8DnLH9F3CSI5LsN8/3lwF3NUFyNPDMrs/u6/oF3r2v/we8pDl38Sjg\nuezcbcrvptObWKg9C302X9v23Yn9S32zZ6LdxfbLFtcD25rHl360qv6yeUzrtUlC5+FAp87z/cuA\nNyb5Np3bdX+967MPAuuTfLOqXrF9X1X12STPBL5Fp/fw75vhrhU96jbXhcBfJbkXeNac9Ra6DHP7\nZx+iM3y2o7ZJrXlpsCSpNYe5JEmtGSaSpNYME0lSa4aJJKk1w0SS1JphIklqzTCRJLVmmEiSWvv/\nj38xtEoTOxAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1f838f4b630>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "### 绘图\n",
    "PlotInit()\n",
    "PlotDistance()\n",
    "plt.show()\n",
    "######################################################################"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Empty",
   "language": "python",
   "name": "empty"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
